package cn.edu.suda.ada.common.config;

import java.util.HashMap;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import cn.edu.suda.ada.database.exception.DatabaseException;

public abstract class DefaultConfig implements Config {
	/**
	 * 日志
	 */
	protected static Logger logger = LogManager.getLogger("edu.suda.ada.common");
	protected static Map<String, Config> configs = new HashMap<String, Config>();
	protected Config config;
	
	public enum ConfigType {
		PROPERTIES
	}
	
	public static Config getConfig(ConfigType type, String path) throws DatabaseException{
		Config config = configs.get(path);
		if (null == config) {
			switch(type) {
			case PROPERTIES:
				config = new PropertiesConfig(path);
				configs.put(path, config);
			}
		}
		return config;
	}
	
	@Override
	public Boolean getBoolean(String key) {
		return Boolean.parseBoolean(getString(key));
	}

	@Override
	public Integer getInteger(String key){
		return Integer.parseInt(getString(key));
	}

	@Override
	public Long getLong(String key){
		return Long.parseLong(getString(key));
	}

	@Override
	public Double getDouble(String key){
		return Double.parseDouble(getString(key));
	}
}
